package com.kede.api.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.kede.api.order.service.ICerManageService;
import com.kede.domain.ZhiGoodValidDomain;
import com.kede.domain.ZhiGoodValidFailDomain;
import com.kede.ienum.order.CertiTypeEnum;
import com.kede.pojo.GoodValidFailStatus;
import com.kede.pojo.PagePO;
import com.kede.pojo.ResHttp;
import com.kede.service.ZhiGoodValidFailService;
import com.kede.service.ZhiGoodValidService;
import com.kede.utils.CollectionUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:Pr.li
 * @Date: create in 2023/10/20 17:40
 */
@Service
public class CerManageServiceImpl implements ICerManageService {


    @Resource
    private ZhiGoodValidService zhiGoodValidService;

    @Resource
    private ZhiGoodValidFailService zhiGoodValidFailService;


    @Override
    public ResHttp getStoreValidOrderFail(PagePO page, Integer cerId, CertiTypeEnum type) {
        List<OrderItem> orders = page.orders();
        if (CollectionUtil.Blank(orders)){
            orders.add(OrderItem.desc("create_time"));
        }
        LambdaQueryWrapper<ZhiGoodValidFailDomain> queryWrapper = new LambdaQueryWrapper<>();
        switch (type){
            case STORE:
                queryWrapper.eq(ZhiGoodValidFailDomain::getStoreId,cerId);
                break;
            case QUDAI:
                queryWrapper.eq(ZhiGoodValidFailDomain::getQuId,cerId);
                break;
            case SHIDAI:
                queryWrapper.eq(ZhiGoodValidFailDomain::getShiId,cerId);
                break;
        }
        queryWrapper.eq(ZhiGoodValidFailDomain::getStatus, GoodValidFailStatus.SURE.getStatus());
        PagePO<ZhiGoodValidFailDomain> page1 = zhiGoodValidFailService.page(page, queryWrapper);
        return ResHttp.okData(page1);
    }

    @Override
    public ResHttp getStoreValidOrder(PagePO page, Integer cerId,CertiTypeEnum type) {
        List<OrderItem> orders = page.orders();
        if (CollectionUtil.Blank(orders)){
            orders.add(OrderItem.desc("create_time"));
        }
        LambdaQueryWrapper<ZhiGoodValidDomain> queryWrapper = new LambdaQueryWrapper<>();
        switch (type){
            case STORE:
                queryWrapper.eq(ZhiGoodValidDomain::getStoreId,cerId);
                break;
            case QUDAI:
                queryWrapper.eq(ZhiGoodValidDomain::getQuId,cerId);
                break;
            case SHIDAI:
                queryWrapper.eq(ZhiGoodValidDomain::getShiId,cerId);
                break;
        }
        PagePO<ZhiGoodValidFailDomain> page1 = zhiGoodValidService.page(page, queryWrapper);
        return ResHttp.okData(page1);
    }
}
